﻿<div id="add">
    <form role="form">
        <div class="form-group">
            <label for="name">姓名</label>
            <input type="text" class="form-control" id="name"
                   placeholder="请输入名称">
        </div>
        <div class="form-group">
            <label for="name">年龄</label>
            <input type="text" class="form-control" id="age"
                   placeholder="请输入年龄">
        </div>
        <div class="form-group">
            <label for="name">性别     </label>

            <input type="radio" name="optionsRadios" id="optionsRadios1" value="男" checked> 男


            <input type="radio" name="optionsRadios" id="optionsRadios2" value="女">女

        </div>

        <div class="form-group">
            <label for="name">选择部门</label>
            <select class="form-control" v-model="dpmdata.did" id="bumen">
                <option v-for="dpm in dpmdata" v-bind:value="dpm.did">{{dpm.department}}</option>

            </select>
            <label for="name">职位</label>
            <select class="form-control" v-model="ptndata.pid" id="zhiwei">
                <option v-for="ptn in ptndata" v-bind:value="ptn.pid">{{ptn.position}}</option>

            </select>
        </div>
        <div class="form-group">
            <label for="name">备注</label>
            <textarea class="form-control" rows="3" id="SRemark"></textarea>
        </div>

    </form>
    <button type="button" class="btn btn-primary"
            data-dismiss="modal" v-on:click="addsf">
        提交
    </button>
</div>
<script src="~/js/qs.min.js"></script>
<script>
   
    new Vue({
        el: '#add',
        data() {
            return {
                dpmdata: [],
                ptndata: [],
                sf:
                {
                    SSerial: "",
                    SName:"",
                    SSex: "",
                    SAge: "",
                    SPosition: "",
                    SRemark: ""

                }
            }
        },
        mounted() {//页面加载成功事件
            function dt() {
                return axios
                .get('/Personnel/Departmentshow');
            }
            function ps() {
                return axios
                    .get('/Personnel/Positionshow');
            }            
            axios.all([dt(),ps()])
                
                .then(axios.spread((dpmdata, ptndata) => {
                    this.dpmdata = dpmdata.data;
                    this.ptndata = ptndata.data;
                }))
                    .catch(function (error) {
                        console.log(error);
                    })
        },
   
        methods: {
            addsf: function () {
                var myDate = new Date();
                var a=myDate.getYear();        //获取当前年份(2位)
              
                var b= myDate.getMonth();       //获取当前月份(0-11,0代表1月)
                myDate.getDate();        //获取当前日(1-31)
                myDate.getDay();         //获取当前星期X(0-6,0代表星期天)
                var c=myDate.getTime();        //获取当前时间(从1970.1.1开始的毫秒数)
                myDate.getHours();       //获取当前小时数(0-23)
                myDate.getMinutes();     //获取当前分钟数(0-59)
                myDate.getSeconds();     //获取当前秒数(0-59)
                myDate.getMilliseconds();    //获取当前毫秒数(0-999)
                myDate.toLocaleDateString();     //获取当前日期
                var mytime = myDate.toLocaleTimeString();     //获取当前时间
                myDate.toLocaleString();        //获取日期与时间
                var obj = {
                    SSerial: "YG_" +a+b+c,
                    SName: $("#name").val(),
                    SSex: $('input[name="optionsRadios"]:checked').val(),
                    SAge: $("#age").val(),
                    SPosition: this.ptndata.pid,
                    SRemark: $("#SRemark").val(),
                    
                };
              
                axios
                    .post("/personnel/Add", window.Qs.stringify(obj))
                    .then(
                        function (i) {
                            if (i.data > 0) {
                                alert("添加成功");
                                location.href = '/Personnel/HomeIndex'
                            }
                            else {
                                alert("添加失败");
                            }
                        }

                    )
            }

        }

    })


</script>